package com.atguigu.gulimall.order.vo;

import lombok.Data;
import org.springframework.util.CollectionUtils;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * @author ming
 * @create 2022/5/9
 * @description:
 */
@Data
public class OrderConfirmVo {
    //收获地址
    private List<MemberAddressVo> address;
    //所有选中的购物项
    private List<OrderItemVo> items;

    //发票记录

    //优惠券信息
    private Integer integration;

    //订单总额
    private BigDecimal total;

    //应付价格
    private BigDecimal payPrice;
    //库存信息
    private Map<Long,Boolean> stocks;

    //数量
    private Integer count;
    //订单防重令牌(防止重复提交)
    private String orderToken;


    public BigDecimal getTotal() {
        BigDecimal sum = new BigDecimal("0");
        if(!CollectionUtils.isEmpty(items)){
            for (OrderItemVo item : items) {
                BigDecimal multiply = item.getPrice().multiply(new BigDecimal(item.getCount()));
                sum = sum.add(multiply);
            }
        }
        return sum; 

    }
    public BigDecimal getPayPrice(){
        return getTotal();
    }

    public Integer getCount(){
        if(!CollectionUtils.isEmpty(items)){
            Integer i = 0;
            for (OrderItemVo item : items) {
                i+=item.getCount();
            }
            return i;
        }
        return 0;

    }
    
    
}
